package com.lemon.smartsafetynew.ui.fragment.hidden;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.lemon.smartsafety.R;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by Andrew on 2017/9/7.
 */

public class SafeHiddenDoneFragment extends BaseFragment {

    @Bind(R.id.top_layout)
    LinearLayout topLayout;
    @Bind(R.id.one_btn)
    Button oneBtn;
    @Bind(R.id.two_btn)
    Button twoBtn;
    @Bind(R.id.three_btn)
    Button threeBtn;

    private int mCurrentDrawId;

    public static SafeHiddenDoneFragment newInstance() {

        Bundle args = new Bundle();

        SafeHiddenDoneFragment fragment = new SafeHiddenDoneFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void getBaseArguments() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_top_button;
    }

    @Override
    protected void initViews() {

        initBtn();
        initFragment();

    }

    @OnClick({R.id.one_btn, R.id.two_btn, R.id.three_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.one_btn:   //全部

                disSelected(mCurrentDrawId);
                transactionFragment(SafeHiddenListFragment.newInstance(1, 0));
                mCurrentDrawId = R.id.one_btn;
                select(mCurrentDrawId);

                break;
            case R.id.two_btn:   //未上报

                disSelected(mCurrentDrawId);
                transactionFragment(SafeHiddenListFragment.newInstance(1, 1));
                mCurrentDrawId = R.id.two_btn;
                select(mCurrentDrawId);

                break;
            case R.id.three_btn: //已上报

                disSelected(mCurrentDrawId);
                transactionFragment(SafeHiddenListFragment.newInstance(1, 2));
                mCurrentDrawId = R.id.three_btn;
                select(mCurrentDrawId);

                break;
        }
    }


    private void transactionFragment(Fragment fragment) {
        getChildFragmentManager().beginTransaction().replace(R.id.content_layout, fragment).commit();
    }

    private void disSelected(int id) {
        switch (id) {
            case R.id.one_btn:
                oneBtn.setSelected(false);
                break;
            case R.id.two_btn:
                twoBtn.setSelected(false);
                break;
            case R.id.three_btn:
                threeBtn.setSelected(false);
                break;
        }
    }

    private void select(int id) {
        switch (id) {
            case R.id.one_btn:
                oneBtn.setSelected(true);
                break;
            case R.id.two_btn:
                twoBtn.setSelected(true);
                break;
            case R.id.three_btn:
                threeBtn.setSelected(true);
                break;
        }
    }


    private void initBtn() {

        topLayout.setVisibility(View.GONE);
        oneBtn.setVisibility(View.GONE);
        twoBtn.setVisibility(View.GONE);
        threeBtn.setVisibility(View.GONE);

        oneBtn.setText(getString(R.string.hidden_all));
        twoBtn.setText(getString(R.string.hidden_not_upload));
        threeBtn.setText(getString(R.string.hidden_has_uploaded));

    }

    private void initFragment() {

        transactionFragment(SafeHiddenListFragment.newInstance(1, 0));
        mCurrentDrawId = R.id.one_btn;
        select(mCurrentDrawId);
    }

}
